package metrics;

import plots.Edge;
import plots.Plot;
import edu.uci.ics.jung.graph.UndirectedGraph;
import base.Environment;

/**
 * Computes how efficiently the environment was farmed from the agents perspective.
 * Everything farmed == success - for them.
 *
 */
public class ResourceUsageEfficiency extends EnvironmentMetric {

	public ResourceUsageEfficiency(Environment env){
		super(env);
	}
	
	@Override
	protected double computeScore() {
		double result = 0d;		
		double farmed = 0d;		
		
		UndirectedGraph<Plot, Edge> plots = env.getPlots();		
		double landState = 0d;
		
		for(Plot x:plots.getVertices()) {	
			farmed = 1 - x.getYield()/x.getMaxYield();
			landState += farmed;			
		}
		
		result = landState/plots.getVertexCount()*100;
		
		return Double.isNaN(result) ? 100D : result;

	}
	
	@Override
	public String toString(){
		String result= "@ Resource Usage Efficiency: " + computeScore() +"%";
		
		return result;
	}


}
